#!/usr/bin/env php
<?php
    require 'cli-config.php';

    // Requires

    // Credentials
    $c1 = new Credential;
    $c1->setName('admin_index');
    $em->persist($c1);

    $c2 = new Credential;
    $c2->setName('admin_credentials');
    $em->persist($c2);

    $c3 = new Credential;
    $c3->setName('admin_users');
    $em->persist($c3);

    $c4 = new Credential;
    $c4->setName('admin_news');
    $em->persist($c4);

    $c5 = new Credential;
    $c5->setName('admin_forum');
    $em->persist($c5);

    $c20 = new Credential;
    $c20->setName('forums_edit');
    $em->persist($c20);

    $c21 = new Credential;
    $c21->setName('forums_delete');
    $em->persist($c21);

    $c22 = new Credential;
    $c22->setName('forums_moderate');
    $em->persist($c22);

    // Groupes
    $p1 = new Group;
    $p1->setName('Administrateurs');
    $p1->addCredentials($c1);
    $p1->addCredentials($c2);
    $p1->addCredentials($c3);
    $p1->addCredentials($c4);
    $p1->addCredentials($c5);
    $p1->addCredentials($c20);
    $p1->addCredentials($c21);
    $p1->addCredentials($c22);
    $em->persist($p1);

    // User
    $user = new User;
    $user->setCreatedAt(new \DateTime('now'));
    $user->setName('Soraya');
    $user->setEmail('soraya@domaine-des-scribes.net');
    $user->setSalt(sha1('admin'));
    $user->setPassword(sha1(sha1('admin'). 'test'));
    $user->setAvatar('/web/upload/images/avatars/test.png');
    $user->addGroups($p1);
    $em->persist($user);

    // Forums
    $categorie1 = new ForumsCategory;
    $categorie1->setTitle('Catégorie de forums');
    $categorie1->setPos(1);
    $em->persist($categorie1);

    $forum1 = new Forum;
    $forum1->setTitle('Premier forum de test');
    $forum1->setCategory($categorie1);
    $forum1->setImage('web/upload/images/prasen10.jpg');
    $forum1->setDescription('Description de forum pas trop longue, il pourra y avoir une image aussi');
    $forum1->setAccess(0);
    $forum1->setPos(1);
    $em->persist($forum1);

    $discussion1 = new ForumsDiscussion;
    $discussion1->setUser($user);
    $discussion1->setCreatedAt(new Datetime);
    $discussion1->setTitle('Sujet de discussion');
    $discussion1->setForum($forum1);
    $em->persist($discussion1);

    $message1 = new ForumsMessage;
    $message1->setUser($user);
    $message1->setCreatedAt(new Datetime);
    $message1->setContent('Contenu de la discussion ici, on peut y raconter des choses intéressantes ou pas d\'ailleurs...');
    $message1->setDiscussion($discussion1);
    $em->persist($message1);

    $forum2 = new Forum;
    $forum2->setTitle('Forum réservé aux gens connectés');
    $forum2->setCategory($categorie1);
    $forum2->setDescription('Description du forum réservé aux membres connectés !');
    $forum2->setAccess(1);
    $forum2->setPos(2);
    $em->persist($forum2);


    // Articles
    $cat1 = new ArticlesCategory;
    $cat1->setTitle('Catégorie d\'articles 1');
    $cat1->setPos(1);
    $em->persist($cat1);

    $em->flush();